Command-line Environment
-
Job Control
-
Killing a process
Ctrl-C: deliver a SIGINT signal to the process.- use the SIGQUIT signal instead, by typing
Ctrl-\ - Note that
^is howCtrlis displayed when typed in the terminal. - a more generic signal for asking a process to exit gracefully is the
SIGTERMsignalkill -TERM <PID>
-
Pausing and backgrounding processes
-
typing
Ctrl-Zwill prompt the shell to send aSIGTSTPsignal -
continue the paused job in the foreground or in the background using
fgorbg -
The
jobscommand lists the unfinished jobs associated with the current terminal session.- use
pgrepto find that out
- use
-
refer to the last backgrounded job you can use the
$!special parameter -
the
&suffix in a command will run the command in the background -
To background an already running program you can do
Ctrl-Zfollowed bybg.SIGHUPnohup(a wrapper to ignoreSIGHUP), or usedisownif the process has already been started
-
other signals here or typing
man signalorkill -l.
-
-
-
Terminal Multiplexers
Terminal multiplexers like
tmuxallow you to multiplex terminal windows using panes and tabs so you can interact with multiple shell sessions.- keybindings: the form
<C-b> xwhere that means (1) pressCtrl+b, (2) releaseCtrl+b, and then (3) pressx. - hierarchy of objects:
- Sessions - an independent workspace with one or more windows
tmuxstarts a new session.tmux new -s NAMEstarts it with that name.tmux lslists the current sessions- Within
tmuxtyping<C-b> ddetaches the current session tmux aattaches the last session. You can use-tflag to specify which
- Windows - tabs in editors or browsers, they are visually separate parts of the same session
<C-b> cCreates a new window. To close it you can just terminate the shells doing<C-d><C-b> NGo to the N th window. Note they are numbered<C-b> pGoes to the previous window<C-b> nGoes to the next window<C-b> ,Rename the current window<C-b> wList current windows
- Panes - Like vim splits, panes let you have multiple shells in the same visual display.
<C-b> "Split the current pane horizontally<C-b> %Split the current pane vertically<C-b> <direction>Move to the pane in the specified direction. Direction here means arrow keys.<C-b> zToggle zoom for the current pane<C-b> [Start scrollback. You can then press<space>to start a selection and<enter>to copy that selection.<C-b> <space>Cycle through pane arrangements.
- Sessions - an independent workspace with one or more windows
- here is a quick tutorial on
tmuxand this has a more detailed explanation that covers the originalscreencommand.
- keybindings: the form
-
Aliases
-
Aliases have many convenient features:
-
# Make shorthands for common flags alias ll="ls -lh" # Save a lot of typing for common commands alias gs="git status" alias gc="git commit" alias v="vim" # Save you from mistyping alias sl=ls # Overwrite existing commands for better defaults alias mv="mv -i" # -i prompts before overwrite alias mkdir="mkdir -p" # -p make parent dirs as needed alias df="df -h" # -h prints human readable format # Alias can be composed alias la="ls -A" alias lla="la -l" # To ignore an alias run it prepended with \ \ls # Or disable an alias altogether with unalias unalias la # To get an alias definition just call it with alias alias ll # Will print ll='ls -lh' -
include it in shell startup files, like
.bashrcor.zshrc,
-
-
Dotfiles
-
For
bash, editing your.bashrcor.bash_profilewill work in most systems.PATHenvironment, likeexport PATH="$PATH:/path/to/program/bin"
-
git-~/.gitconfig -
vim-~/.vimrcand the~/.vimfolder -
ssh-~/.ssh/config -
tmux-~/.tmux.conf -
in their own folder, under version control, and symlinked into place using a script
-
Portability
-
-
Remote Machines
-
SSH is highly configurable so it is worth learning about it.
-
SSH Keys:
~/.ssh/id_rsa-
Key generation: run
ssh-keygen.-
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519
-
-
Key based authentication
sshwill look into.ssh/authorized_keysto determine which clients it should let inssh-copy-id
-
-
Copying files over SSH
-
Port Forwarding
-
SSH Configuration
-
alias my_server="ssh -i ~/.id_ed25519 --port 2222 -L 9999:localhost:8888 foobar@remote_server- a better alternative using
~/.ssh/config. - be thoughtful about sharing your SSH configuration.
- a better alternative using
-
-
-
Shells & Frameworks
bash,zsh/ fish/- general frameworks are prezto or oh-my-zsh
- zsh-syntax-highlighting or zsh-history-substring-search
- One thing to note when using these frameworks is that they may slow down your shell
-
Terminal Emulators